//
//  SessionManager.m
//  ExhibitForcePrototype
//
//  Created by Georgi Bachvarov on 12/5/12.
//  Copyright (c) 2012 Dilyana Todorova. All rights reserved.
//

#import "SessionManager.h"

@interface SessionManager (){
    
}



@end

@implementation SessionManager


static SessionManager * sharedInstance;

+ (SessionManager *)sharedInstance {
    if (!sharedInstance) {
        @synchronized(self) {
            if (!sharedInstance) {
                sharedInstance = [[super allocWithZone:NULL] init];
            }
        }
    }
    return sharedInstance;
}

- (id)init {
    self = [super init];
    if (self) {
    }
    return self;
}

- (void)validateSessionWithUsername:(NSString *)username andPassword:(NSString *)password{
    self.username = username;
    self.isValidSession = YES;
    int64_t delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [self.delegate sessionManagerDidValidateUsername:self.username];
    });
}

- (void)invalidateSession{
    self.isValidSession = NO;
    self.username = nil;
}

@end
